# $Id: PKGBUILD 88676 2013-04-21 22:16:43Z heftig $
# Maintainer: Sergej Pupykin <pupykin.s+arch@gmail.com>
# Contributor: Vitaliy Berdinskikh ur6lad[at]i.ua
# Contributor: Michael Fellinger <m.fellinger@gmail.com>

pkgname=couchdb
pkgver=1.2.2
pkgrel=2
pkgdesc="A document-oriented database that can be queried and indexed in a MapReduce fashion using JSON"
arch=('i686' 'x86_64')
url="http://couchdb.apache.org"
license=('APACHE')
depends=('icu' 'erlang' 'js' 'openssl' 'curl')
install=couchdb.install
options=('!libtool')
backup=('etc/couchdb/local.ini'
	'etc/conf.d/couchdb'
	'etc/logrotate.d/couchdb')
source=("http://apache-mirror.rbc.ru/pub/apache/couchdb/source/$pkgver/apache-couchdb-$pkgver.tar.gz"{,.asc}
	"couchdb.service"
	"couchdb.tmpfiles"
	"couchdb.rc"
	"build-fix.patch")
md5sums=('6cc49c22fadcf7d8cf8aa34dae71b203'
         '1346a657d7552188f6cc9e0cdc231b05'
         '8914a7ffc6745f94106d96206709acb4'
         '1e254ebe32eeb061be64193bafa35dbf'
         'a75ee9b310a950eea13b07274b7a0669'
         '71afe48505dfc07ba2091786b4650fa2')

build() {
  cd "$srcdir/apache-$pkgname-$pkgver"
  patch -p1 <$srcdir/build-fix.patch
  ./configure --prefix=/usr \
    --sysconfdir=/etc \
    --localstatedir=/var
  make
}

package() {
  cd "$srcdir/apache-$pkgname-$pkgver"
  make DESTDIR="$pkgdir" install

  install -Dm644 etc/default/couchdb $pkgdir/etc/conf.d/couchdb
  sed -i 's|\(COUCHDB_OPTIONS=\)|\1"-p /var/run/couchdb/couchdb.pid"|' $pkgdir/etc/conf.d/couchdb

  install -Dm755 $srcdir/couchdb.rc $pkgdir/etc/rc.d/couchdb

  rm -rf $pkgdir/etc/default/ $pkgdir/var/run

  install -Dm0644 $srcdir/$pkgname.service $pkgdir/usr/lib/systemd/system/$pkgname.service
  install -Dm0644 $srcdir/$pkgname.tmpfiles $pkgdir/usr/lib/tmpfiles.d/$pkgname.conf
}
